//
//  Comment.m
//  DialectShare
//
//  Created by timmy zhong on 4/1/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Comment.h"
#import "Const.h"
#import "UserDB.h"

@implementation Comment
@synthesize dialectId = _dialectId, uid = _uid, dateline = _dateline, commentId = _commentId;
@synthesize content = _content, user = _user;

- (void)dealloc
{
    self.content = nil;
    self.user = nil;
    
    [super dealloc];
}

- (User *)user
{
    if (_user == nil) {
    
        UserDB *db = [[UserDB alloc] init];
        _user = [[db userOfID:self.uid] retain];
        [db release];
    }
    
    return _user;
}

+ (Comment *)commentWithDic:(NSDictionary *)dic
{
    Comment *cm = [[Comment alloc] init];
    cm.dialectId = [[dic objectForKey:CommentDiaelctId] intValue];
    cm.uid = [[dic objectForKey:CommentUid] intValue];
    cm.dateline = [[dic objectForKey:CommentDateline] intValue];
    cm.content = [dic objectForKey:CommentContent];
    cm.commentId = [[dic objectForKey:CommentId] intValue];
    
    return [cm autorelease];
}

@end
